/* TCSS 590A - Cybernetics and Systems
 * Group Project - Modeling
 * By Barry Jones, Naren Meadem, Michael Pitts, Yuan Tao
 * Fall 2012, University of Washington, Tacoma
 */
package model.delayed;


/**
 * An Event which has an associated value and time.
 * @author Michael Pitts
 * @version Nov 16, 2012
 */
public class Event implements Comparable<Event>
{
	
	/** The value for this event.*/
	public final long value;
	
	/** The time this event goes off.*/
	public final long time;
	
	/** The Account to pay to, or if null check sign of value.  
	 * Negative indicates an expense, positive indicates income.*/
	public final Account account;
	
	/**
	 * Creates a new Event.
	 * @param the_value is the value associated with the Event.
	 * @param the_time is the time associated with the Event.
	 * @param the_account is the savingsAccount to pay to, if null pay to either expenses
	 * or wages.
	 */
	public Event(final long the_value, final long the_time, final Account the_account)
	{
		value = the_value;
		time = the_time;
		account = the_account;
	}
	
	/**
	 * Creates a new event which is either wages or expenses depending on the value.
	 * @param the_value if positive, a wage, otherwise an expense.
	 * @param the_time is the time associated with this event.
	 */
	public Event(final long the_value, final long the_time)
	{
		this(the_value, the_time, null);
	}

	@Override public int compareTo(Event o)
	{
		return (int) (time - o.time);
	}
	
	@Override public boolean equals(final Object o)
	{
		if(! Event.class.isInstance(o)) return false;
		final Event e = (Event) o;
		return time == e.time && value == e.value &&
				((account == null && e.account == null) || 
					(account != null && e.account != null && 
							account.equals(e.account)));
	}
}
